﻿/***************************************************
//  Copyright (c) Premium Tax Free 2011
***************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace PremierTaxFree.PTFLib.Extensions
{
    public static class CollectionsEx
    {
        public static bool IsEmpty<T>(this ICollection<T> list)
        {
            return list.Count == 0;
        }

        public static string ToString(this IList list, string devider, Func<object, string> funct)
        {
            if (list == null || list.Count == 0)
                return string.Empty;

            StringBuilder b = new StringBuilder();
            for (int i = 0; i < list.Count - 1; i++)
            {
                b.Append(funct != null ? funct(list[i]) : list[i]);
                b.Append(devider);
            }

            return b.ToString();
        }
    }
}
